package com.example.boot.mapper

import com.example.boot.domain.User
import com.example.boot.dto.UserDTO
import org.mapstruct.*

@Mapper(
    componentModel = "spring",
    nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT,
    nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
)
interface UserMapper {

//    @Mapping(target = "name", expression = "java(userDTO.getName().trim())")
//    @Mapping(source = "name", target = "name", qualifiedByName = arrayOf("doTrim"))
    fun convertToDomain(userDTO: UserDTO): User

    fun convertToDTO(user: User): UserDTO

    companion object {
        @JvmStatic
        @Named("doTrim")
        fun doTrim(str: String): String {
            return str.trim()
        }
    }
}